package com.cc.utils;


import com.cc.support.LibaryProperties;
import com.cc.support.dto.ShowTableDto;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @User c.c
 * @Since 2022/8/15
 * @Time 13:39
 * @Description 根据用户输入转换成excell中间工具
 */

public class DbTransToExcellUtils {
  /**
   * 获取库下，所有表的"结构"数据
   *
   * @param
   * @return
   * @author C.c
   * @since 2022-08-16 16:27
   **/
  public static List<ShowTableDto> getLibraryAllTableStruct(LibaryProperties libaryProperties, String tableName) {
    List<ShowTableDto> tablelist = null;

    try {
      tablelist = libaryProperties.get(tableName).stream().map(e -> {
        return new ShowTableDto(e.getColumnComment(), e.getColumnName(), e.getColumnType(), e.getCharacterMaximumLength(), e.getTableName());
      }).collect(Collectors.toList());
    } catch (Exception e) {

      String msg = String.format("数据库:[%s], 不存在表:[%s]", libaryProperties.getTableStructs().get(0).getTableSchema(), tableName);
      throw new RuntimeException(msg);
    }

    return tablelist;
  }

}
